package com.tj.bo.trade.server.service.rule;

import com.fqgj.common.utils.CollectionUtils;
import com.fqgj.common.utils.DateUtil;
import com.tj.bo.trade.client.enums.OrderStatusEnum;
import com.tj.bo.trade.client.enums.TradeTypeEnum;
import com.tj.bo.trade.server.entity.BinaryTradeEntity;
import com.tj.bo.trade.server.entity.bussiness.TradeDailyAvgEntity;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 青铜 累计日均净利润大于2倍件均
 * Author: Amarendar
 * Date: 2020/8/25 上午11:01
 */
@Service
public class TradeBronzeRule2 extends BaseTradeRule {

    private static final String RULE_NAME = "累计日均净利润大于2倍件均";

    private static final Integer DEFAULT_PRIORITY = 3;

    @Override
    public void checkRouterRule(RouterContext routerContext, List<RuleResultVO> ruleResultVOList) {

        TradeDailyAvgEntity tradeDailyAvgEntity = binaryTradeDao.selectTradeDailyAvg(routerContext.getUserCode(), routerContext.getProductCode());
        if (tradeDailyAvgEntity == null || tradeDailyAvgEntity.getDays() == 0
                || tradeDailyAvgEntity.getTotalOrderNum() < redisConfigUtil.getChangeOddsUserTradeNumbers()) {
            ruleResultVOList.add(new RuleResultVO(routerContext.getProductCode(), RULE_NAME).setMessage("订单数过少"));
            return;
        }

        if (tradeDailyAvgEntity.getDailyAvgProfit().doubleValue() > tradeDailyAvgEntity.getAverageOrderAmount().doubleValue() * 2) {
            RuleResultVO ruleResultVO = new RuleResultVO(routerContext.getProductCode(), RULE_NAME);
            ruleResultVO.setPriority(DEFAULT_PRIORITY);
            ruleResultVO.setMode(0);
            ruleResultVO.setChangeValue(BigDecimal.valueOf(-0.05));
            ruleResultVO.setMessage("累计日均净利润大于2倍件均");
            ruleResultVOList.add(ruleResultVO);
        } else {
            ruleResultVOList.add(new RuleResultVO(routerContext.getProductCode(), RULE_NAME).setMessage("累计日均净利润大于2倍件均-条件不满足"));
        }

    }
}
